package com.kmproject.haifu.mvp.ui.holder;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.ArrayList;
import java.util.List;

public class BannerViewHolder<T extends HouseRentListShowInfoBean.HouseImageListBean> implements MZViewHolder<T> {
    private ImageLoader imageLoader;
    ImageView ivBanner;
    private List<HouseRentListShowInfoBean.HouseImageListBean> baseBeans=new ArrayList<>();

    @Override
    public View createView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.image_item, null, false);
        ivBanner=view.findViewById(R.id.image_item_img);
        imageLoader = ArmsUtils.obtainAppComponentFromContext(context).imageLoader();
        return view;
    }
    public void setBaseBeans(List<HouseRentListShowInfoBean.HouseImageListBean> mbaseBeans){
        this.baseBeans=mbaseBeans;
    }

    @Override
    public void onBind(Context context, int i, T s) {
        if (ivBanner != null) {
            imageLoader.loadImage(context, ImageConfigImpl.builder().
                    imageView(ivBanner)
                    .isCenterCrop(false)
                    .url((((HouseRentListShowInfoBean.HouseImageListBean)s).getImageUrl()))
                    .build());
            ivBanner.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AppUtil.lookBigImg((Activity) context,(((HouseRentListShowInfoBean.HouseImageListBean)s).getImageUrl()),getPaths());
                }
            });

        }
    }

    /**
     * 获取所有路径
     * @return
     */
    public List<String> getPaths(){
        List<String> temPaths=new ArrayList<>();
        for (HouseRentListShowInfoBean.HouseImageListBean  imageListBean:baseBeans)
        {
            temPaths.add(imageListBean.getImageUrl());
        }
        return temPaths;
    }
}
